package org.xg.study.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author CMG
 * @version 1.0
 * @description
 * @cLassName RequestLine
 * @date 2021/9/23 17:10
 **/
@WebServlet("/requestLine")
public class RequestLine extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter printWriter = resp.getWriter();
        printWriter.write("请求方式：" + req.getMethod() + "<br/>" +
                "客户端IPD地址：" + req.getRemoteAddr() + "<br/>" +
                "应用名称（上下文）：" + req.getContextPath() + "<br/>" +
                "URI：" + req.getRequestURI() + "<br/>" +
                "请求字符串：" + req.getQueryString() + "<br/>" +
                "Servlet所映射的路径：" + req.getServletPath() + "<br/>" +
                "客户端的完整主机名：" + req.getRemoteHost() + "<br/>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
